package dk.datainfusion.cprtest;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

import dk.datainfusion.cprtest.model.VejRecord;
import dk.datainfusion.cprtest.model.VejRecordFactory;

public class RecordReader {

	public Set<VejRecord> readRecordsFromStream(InputStream fstream)
			throws IOException {
		DataInputStream in = new DataInputStream(fstream);
		BufferedReader br = new BufferedReader(new InputStreamReader(in));
		Set<VejRecord> set = new HashSet<VejRecord>();
		String strLine;
		// Read File Line By Line
		
		while ((strLine = br.readLine()) != null) {
			VejRecord vejRecord = VejRecordFactory.createRecord(strLine);
			if(vejRecord!=null) {
				set.add(vejRecord);
			}
		}
		// Close the input stream
		in.close();
		return set;

	}

}
